﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using PMS.XCMG.Entity;
using PMS.XCMG.IBusiness;
using PMS.XCMG.Util;
using PMS.XCMG.Models;

namespace PMS.XCMG.Business
{
    public class CF_EnumItemBusiness : BusRepository<CF_EnumItem>, ICF_EnumItemBusiness, IScopedDependency
    {
        private IServiceProvider SvcProvider { get; set; }
        public CF_EnumItemBusiness(GDbContext context, IServiceProvider svcProvider)
            : base(context)
        {
            this.SvcProvider = svcProvider;
        }

        public Task<PageResult<CF_EnumItem>> GetPageResultAsync(PageInput<CF_EnumItemQM> query)
        {
            var queryable = this.GetQueryable(true);
            var search = query.Search;
            if (!search.EnumId.IsNullOrEmpty())
                queryable = queryable.Where(w => w.EnumId == search.EnumId);
            if (!search.Keyword.IsNullOrEmpty())
                queryable = queryable.Where(w => w.Name.Contains(search.Keyword) || w.Code.Contains(search.Keyword));

            return this.GetPageResultAsync(queryable, query);
        }

        public async Task<List<CF_EnumItem>> GetByNameAsync(string whseId,string enumId)
        {
            return await this.GetQueryable(true).Where(w => w.CompanyId == whseId && w.EnumId == enumId).ToListAsync();
        }
    }
}

